import axios from "axios";
const state = {
    goodsTypeList: [],
    shopByTypeId: [],
    goodsList: []
}
const mutations = {
    //将获取到的商品类别数据存入goodsTypeList
    CHANGE_GOODS_TYPE_LIST(state, goodsTypeList) {
        state.goodsTypeList = goodsTypeList;
    },
    //将通过店铺id获取到的商品类型数据存入shopByTypeId
    CHANGE_SHOP_BY_TYPE_ID(state, goodsTypeList) {
        state.shopByTypeId = goodsTypeList;
    },
    CHANGE_GOODS_LIST(state, goodsList) {
        state.goodsList = goodsList;
    }
}

const actions = {
    //提交添加商品类别的方法
    submitGoodsType(state, params) {
        // console.log(state);
        return axios.post('/goodsTypeList', params);
    },
    //获取商品类别数据列表
    getGoodsTypeList({ commit }, params) {
        axios.get('/goodsTypeList', { params }).then(res => {
            // console.log(res);
            commit('CHANGE_GOODS_TYPE_LIST', res.getList);
            commit('CHANGE_PAGE_INDEX', res.pageIndex);
        });
    },
    //根据店铺id获取商品类型列表
    allgetgoodsTypeListByTypeId({ commit }, shopId) {
        axios.get('/goodsTypeList/' + shopId).then(res => {
            // console.log(res.goodsTypeList);
            commit('CHANGE_SHOP_BY_TYPE_ID', res.goodsTypeList);
        })
    },
    //获取商品列表数据
    getGoodsList({ commit }, params) {
        axios.get('/goodsList', { params }).then(res => {
            commit('CHANGE_GOODS_LIST', res.getList);
            commit('CHANGE_PAGE_INDEX', res.pageIndex);
            // console.log(res);
        })
    },
    //删除商品类别记录
    deletegoodsTypeList(state, _id) {
        return axios.delete('/goodsTypeList', {
            params: {
                _id
            }
        });
    }
}

export default {
    state,
    mutations,
    actions
}
